package com.wjm.client.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wjm.entity.Desk;
import com.wjm.util.CacheUtil;

@Controller
@RequestMapping("/client/desk")
public class DeskClientController {

	
	@RequestMapping("/query")
	@ResponseBody
	public List<Desk> query(int crId) {
		List<Desk> desks = null;
		try {
			List<Desk> list = CacheUtil.getDesks().get(crId);
			Desk ds = null;
			if (list != null) {
				desks = new ArrayList<>();
				for (Desk desk : list) {
					// 创建新对象是为了不对缓存中的对象造成数据上的影响。
					ds = new Desk();
					ds.setDeskId(desk.getDeskId());
					ds.setDeskNo(desk.getDeskNo());
					// 如果该位置已经有预约，那么就将状态设置为2
					if (CacheUtil.getRecords().get(desk.getDeskId()) != null) {
						ds.setDeskStatus(2);
					}
					desks.add(ds);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return desks;
	}

}
